package org.ufpe.cin.ip.projeto.Util;

import java.util.Random;

import org.ufpe.cin.ip.projeto.Dados.BaseClasses.Carta;
import org.ufpe.cin.ip.projeto.Dados.BaseClasses.CommonPlayer;
import org.ufpe.cin.ip.projeto.Exceptions.ElementNotExistsException;


public class Perfil {
	private int foldChance;
	private int raiseChance;
	private int callChance;
	private int allInChance;
	private double apostaBase;


	public Perfil() {// 20 30 10 40
		do{
		this.foldChance = new Random().nextInt(101);//0-20
		this.raiseChance = new Random().nextInt(76);//21-30+20
		this.callChance = new Random().nextInt(51);//51-10+50
		this.allInChance = new Random().nextInt(26);//61-60+40
		}while((foldChance+callChance+raiseChance+allInChance) != 100);
		this.apostaBase = raiseChance - callChance;
	}

	public void compararCartas(CommonPlayer player, Carta[] cartasComunitarias){
		JogadasComparator comparar = new JogadasComparator(player.getMao(),cartasComunitarias);
		try {
			if(comparar.testRoyalStrightFlush()) {
				foldChance = 0;
				raiseChance = 40;
				callChance = 30;
				allInChance = 30;
			} else if(comparar.testStraightFlush()) {
				foldChance = 1;
				raiseChance = 39;
				callChance = 30;
				allInChance = 30;
			}else if (comparar.isQuadra()) {
				foldChance = 3;
				raiseChance = 37;
				callChance = 30;
				allInChance = 30;
			}else if (comparar.isFullHouse()) {
				foldChance = 5;
				raiseChance = 35;
				callChance = 35;
				allInChance = 30;
			}else if (comparar.isFlush()) {
				foldChance = 10;
				raiseChance = 30;
				callChance = 35;
				allInChance = 25;
			}else if (comparar.isStraight()) {
				foldChance = 25;
				raiseChance = 20;
				callChance = 35;
				allInChance = 20;
			}else if (comparar.isTrinca()) {
				foldChance = 20;
				raiseChance = 25;
				callChance = 35;
				allInChance = 20;
			}else if (comparar.isDoisPares()) {
				foldChance = 25;
				raiseChance = 20;
				callChance = 40;
				allInChance = 15;
			}else if (comparar.isPar()) {
				foldChance = 30;
				raiseChance = 20;
				callChance = 40;
				allInChance = 10;
			} else {
				foldChance = 70;
				raiseChance = 10;
				callChance = 15;
				allInChance = 05;
			}
		}catch (ElementNotExistsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public int getAcao(CommonPlayer player, Carta[] cartas) {
		int result = 0;
		compararCartas(player, cartas);
		Random r = new Random();
		result = (r.nextInt(100) + 1);

		if(result <= getFoldChance()){
			result = 1;
		} else if (result > getFoldChance() && result <= getRaiseChance()){
			result = 2;
		} else if (result > getRaiseChance() && result <= getCallChance()){
			result = 3;
		} else if (result > getCallChance() && result <= getAllInChance()){
			result = 4;
		}

		return result;
	}

	
	public int getFoldChance() {
		return foldChance;
	}

	public void setFoldChance(int foldChance) {
		this.foldChance = foldChance;
	}

	public int getRaiseChance() {
		return raiseChance + foldChance;
	}

	public void setRaiseChance(int raiseChance) {
		this.raiseChance = raiseChance;
	}

	public int getCallChance() {
		return callChance + raiseChance;
	}

	public void setCallChance(int callChance) {
		this.callChance = callChance;
	}

	public int getAllInChance() {
		return allInChance + callChance;
	}

	public void setAllInChance(int allInChance) {
		this.allInChance = allInChance;
	}
	

	public double getApostaBase() {
		return apostaBase;
	}
	

	public void setApostaBase(double apostaBase) {
		this.apostaBase = apostaBase;
	}

	
}
